<?php
/** 
 * 异常/状态攻击辅助类
 * 所有方法返回1成功，0失败。特殊说明除外；
 */
class StatusHelper {
	
	/**
	* 判断是否中任何异常
	* 返回：异常编号，未中异常返回0
	*/
	public static function has_abn($a) {
		global $g_all_spt;
		foreach($g_all_spt as $sid) {
			if($a->before_status[$sid]->on == 1) {
				return $sid;
			}
		}
		return 0;
	}

	/**
	* 判断是否中任何特殊状态
	* 返回：有则返回1，未中任何特殊状态返回0
	*/
	public static function has_spec($a) {
		if($a->before_status[0]->on == 1) return 1; //倒地
		if($a->spec_status[1]->on == 1) return 1; //饥饿
		if($a->spec_status[2]->on == 1) return 1; //异常
		return 0;
	}
	
	/**
	* 判断是否中任何精神系异常
	* 返回：异常编号，未中异常返回0
	*/
	public static function has_mabn($a) {
		global $g_mental_spt;
		foreach($g_mental_spt as $sid) {
			if($a->before_status[$sid]->on == 1) {
				return $sid;
			}
		}
		return 0;
	}
	
	/**
	* 判断是否中任何肉体系异常
	* 返回：异常编号，未中异常返回0
	*/
	public static function has_babn($a) {
		global $g_body_spt;
		foreach($g_body_spt as $sid) {
			if($a->before_status[$sid]->on == 1) {
				return $sid;
			}
		}
		return 0;
	}

	/**
	* 判断是否中任何超级系异常
	* 返回：异常编号，未中异常返回0
	*/
	public static function has_sabn($a) {
		foreach($_SESSION['super_spt'] as $sid) {
			if($a->before_status[$sid]->on == 1) {
				return $sid;
			}
		}
		return 0;
	}

	//部分专有特定技能自动启动函数，根据cid判断。$t：目标对象
	public static function uskill_init($t) {
		switch($t->cid) {
		case 133:{$t->defskill_status[22]->on = 1;$t->defskill_status[22]->started = 0;break;} //蜃気楼
		case 43:{$t->defskill_status[1]->on = 1;$t->defskill_status[1]->started = 0;break;} //外法幻花阵
		case 9:{$t->defskill_status[31]->on = 1;break;} //混沌波动
		case 148:{$t->defafter_status[5]->on = 1;$t->defafter_status[5]->started = 0;break;} //龙神逆鳞
		case 6:{$t->eventskill_status[22]->on = 1;$t->eventskill_status[22]->started = 0;break;} //真全门耐性
		case 26:{$t->defskill_status[8]->on = 1;$t->defskill_status[8]->started = 0;break;} //闇夜のドレス
		case 16:{$t->before_status[97]->on = 1;$t->before_status[97]->started = 0;break;} //観世音の済度
		case 23:{$t->before_status[98]->on = 1;$t->before_status[98]->started = 0;break;} //極·龍脈の秘術
		case 44:{$t->before_status[96]->on = 1;break;} //夜之女王
		case 127:{$t->before_status[95]->on = 1;break;} //满月女王
		default:{break;}
		}
	}
	
	/** 任何能力上升下降技能的先置判断(uudd--上上下下)
	* $t:目标人对象;$mark:相关的before_status状态位 $sk 技能对象
	* 返回0代表不允许继续执行能力升降操作，返回1则允许
	*/
	public static function pre_uudd($t,$mark) {
	
		global $g_bad_status;
		global $g_good_status;

		if(in_array($mark,$g_bad_status) && $t->defskill_status[6]->on == 1) {
			$_SESSION['show'] .= $t->name."受到二十八星宿的守护，不受任何能力下降影响。<br>";
			return 0;
		}
		if($t->defskill_status[24]->on == 1) {
			$_SESSION['show'] .= $t->name."魔法反射镜生效，能力升降效果打消。<br>";
			$t->defskill_status[24]->cancel($t);
			return 0;
		}
		
		if($t->eventskill_status[25]->on == 1) {
			$_SESSION['show'] .= $t->name."受到地獄のマスク的影响，不受任何能力变化影响。<br>";
			return 0;
		}
		
		if(in_array($mark,$g_good_status) && $t->before_status[55]->on == 1) {
			$_SESSION['show'] .= $t->name."魔界の調べ生效，有利状态打消。<br>";
			return 0;
		}
		if($t->before_status[$mark]-> on == 1) {
			$_SESSION['show'] .= $t->before_status[$mark]->name."发动中，不能重复生效。<br>";
			return 0;
		}
		if(CalHelper::ifgroupskill($t) == 11 && in_array($mark,$g_bad_status)) {
			$_SESSION['show'] .= $t->name."英霊の加護发动，能力下降持续减少一回合<br>";
			$t->before_status[$mark]->time -= 1;
		}
		return 1;
	}

	/**
	 * Down
	 * 影响状态位：
	 * before_status[0]
	 * defskill_status[0]
	 */
	public static function down($b,$res=1.25) {
		if($res == 1.25) { 
			if($b->standing == 1) return 0;	//起身中
			if($b->defskill_status[6]->on == 1) {
				$_SESSION['show'] .= $t->name."受到二十八星宿的守护，不倒地。<br>";
				return 0;
			}

			$_SESSION['show'] .= $b->name."倒地！<br>";	
			//一切常规异常被取消
			self::cure_mentalspt($b);	
			self::cure_bodyspt($b);	

			$b->before_status[0]->on = 1;
			$b->defskill_status[0]->on = 1;
			//防御取消
			$b->before_status[2]->cancel($b);
			$b->defskill_status[3]->cancel($b);

			return 1;
		}
		return 0;
	}
	
	/** 力上升20 3回合**/
	public static function str_up_20($a,$sk = NULL) {
		if(self::pre_uudd($a,3) == 0 || self::pre_uudd($a,14) == 0) {
			return 0;
		}
		$v = ($sk->ex == 1) ? 25 : 20;
		$a->str += $v;
		$a->before_status[3]->on = 1;
		if($sk->bufftime == 1) $a->before_status[3]->time += 1;
		$a->before_status[3]->v = $v;
		$_SESSION['show'] .= $a->name."力量上升${v}(剩余".$a->before_status[3]->time."回合)。<p>";
		
		return 3;
	}

	/** 力上升30 3回合**/
	public static function str_up_30($a) {
		if(self::pre_uudd($a,14) == 0 || self::pre_uudd($a,3) == 0 || self::pre_uudd($a,11) == 0) {
			return 0;
		}
		$a->str += 30;
		if($sk->bufftime == 1) $a->before_status[14]->time += 1;
		$a->before_status[14]->on = 1;
		$_SESSION['show'] .= $a->name."力量上升30(剩余3回合)。<p>";
		
		return 14;
	}

	/** 力上升5 3回合**/
	public static function str_up_5($a) {
		if(self::pre_uudd($a,84) == 0) {
			return 0;
		}
		$a->str +=5;
		$a->before_status[84]->on = 1;
		$_SESSION['show'] .= $a->name."力量上升5(剩余3回合)。<p>";
		
		return 84;
	}

	/** 力上升60 3回合**/
	public static function str_up_60($a) {
		if(self::pre_uudd($a,74) == 0) {
			return 0;
		}
		if($a->before_status[3]->on == 1) $a->before_status[3]->cancel($a);
		if($a->before_status[14]->on == 1) $a->before_status[14]->cancel($a);
		$a->str += 60;
		$a->before_status[74]->on = 1;
		$_SESSION['show'] .= $a->name."力量上升60(剩余3回合)。<p>";
		
		return 74;
	}

	/** 力下降20 3回合 **/
	public static function str_down_20($a,$sk = NULL) {
		if(self::pre_uudd($a,4) == 0) {
			return 0;
		}
		$v = ($sk->ex == 1) ? 25 : 20;
		if($a->str-$v >= 0) {
			$a->before_status[4]->v = $v;
			$a->str -= $v;
		} else {
			$a->before_status[4]->v = $a->str;
			$a->str = 0;
		}
		$a->before_status[4]->on = 1;
		$_SESSION['show'] .= $a->name."力量下降${v}(剩余".$a->before_status[4]->time."回合)。<p>";
		
		return 4;
	}

	/** 魔上升20 3回合**/
	public static function mgr_up_20($a,$sk = NULL) {
		if(self::pre_uudd($a,5) == 0 || self::pre_uudd($a,15) == 0) {
			return 0;
		}
		$v = ($sk->ex == 1) ? 25 : 20;
		$a->mgr += $v;
		$a->before_status[5]->on = 1;
		if($sk->bufftime == 1) $a->before_status[5]->time += 1;
		$a->before_status[5]->v = $v;
		$_SESSION['show'] .= $a->name."魔力上升${v}(剩余3回合)。<p>";
		
		return 5;
	}

	/** 魔上升30 3回合**/
	public static function mgr_up_30($a) {
		if(self::pre_uudd($a,15) == 0 || self::pre_uudd($a,5) == 0 || self::pre_uudd($a,11) == 0) {
			return 0;
		}
		$a->mgr +=30;
		$a->before_status[15]->on = 1;
		$_SESSION['show'] .= $a->name."魔力上升30(剩余3回合)。<p>";
		
		return 15;
	}

	/** 魔上升5 3回合**/
	public static function mgr_up_5($a) {
		if(self::pre_uudd($a,85) == 0) {
			return 0;
		}
		$a->mgr +=5;
		$a->before_status[85]->on = 1;
		$_SESSION['show'] .= $a->name."魔力上升5(剩余3回合)。<p>";
		
		return 85;
	}

	/** 魔下降20 3回合 **/
	public static function mgr_down_20($a,$sk = NULL) {
		if(self::pre_uudd($a,6) == 0) {
			return 0;
		}
		$v = ($sk->ex == 1) ? 25 : 20;
		if($a->mgr-$v >= 0) {
			$a->before_status[6]->v = $v;
			$a->mgr -= $v;
		} else {
			$a->before_status[6]->v = $a->mgr;
			$a->mgr = 0;
		}
		$a->before_status[6]->on = 1;
		$_SESSION['show'] .= $a->name."魔力下降${v}(剩余3回合)。<p>";
		
		return 6;
	}

	/** 速上升20 3回合**/
	public static function spd_up_20($a,$sk = NULL) {
		if(self::pre_uudd($a,7) == 0) {
			return 0;
		}
		$v = ($sk->ex == 1) ? 25 : 20;
		$a->spd += $v;
		$a->before_status[7]->on = 1;
		$a->before_status[7]->v = $v;
		if($sk->bufftime == 1) $a->before_status[7]->time += 1;
		$_SESSION['show'] .= $a->name."速度上升${v}(剩余3回合)。<p>";
		
		return 7;
	}

	/** 速上升30 3回合**/
	public static function spd_up_30($a,$sk = NULL) {
		if(self::pre_uudd($a,16) == 0 || self::pre_uudd($a,11) == 0) {
			return 0;
		}
		$a->spd +=30;
		$a->before_status[16]->on = 1;
		if($sk->bufftime == 1) $a->before_status[16]->time += 1;
		$_SESSION['show'] .= $a->name."速度上升30(剩余3回合)。<p>";
		
		return 16;
	}

	/** 速上升5 3回合**/
	public static function spd_up_5($a) {
		if(self::pre_uudd($a,87) == 0) {
			return 0;
		}
		$a->spd +=5;
		$a->before_status[87]->on = 1;
		$_SESSION['show'] .= $a->name."速度上升5(剩余3回合)。<p>";
		
		return 86;
	}

	/** 速下降20 3回合 **/
	public static function spd_down_20($a,$sk = NULL) {
		if(self::pre_uudd($a,8) == 0) {
			return 0;
		}
		$v = ($sk->ex == 1) ? 25 : 20;
		if($a->spd-$v >= 0) {
			$a->before_status[8]->v = $v;
			$a->spd -= $v;
		} else {
			$a->before_status[8]->v = $a->spd;
			$a->spd = 0;
		}
		$a->before_status[8]->on = 1;
		$_SESSION['show'] .= $a->name."速度下降${v}(剩余3回合)。<p>";
		
		return 8;
	}

	/** 耐上升20 3回合**/
	public static function vit_up_20($a,$sk = NULL) {
		if(self::pre_uudd($a,9) == 0) {
			return 0;
		}
		$v = ($sk->ex == 1) ? 25 : 20;
		$a->vit += $v;
		$a->before_status[9]->on = 1;
		$a->before_status[9]->v = $v;
		if($sk->bufftime == 1) $a->before_status[9]->time += 1;
		$_SESSION['show'] .= $a->name."耐上升${v}(剩余3回合)。<p>";
		
		return 9;
	}

	/** 耐上升5 3回合**/
	public static function vit_up_5($a) {
		if(self::pre_uudd($a,86) == 0) {
			return 0;
		}
		$a->vit +=5;
		$a->before_status[86]->on = 1;
		$_SESSION['show'] .= $a->name."耐上升5(剩余3回合)。<p>";
		
		return 87;
	}

	/** 耐下降20 3回合 
	 **/
	public static function vit_down_20($a,$sk = NULL) {
		if(self::pre_uudd($a,10) == 0) {
			return 0;
		}
		$v = ($sk->ex == 1) ? 25 : 20;
		if($a->vit-$v >= 0) {
			$a->before_status[10]->v = $v;
			$a->vit -= $v;
		} else {
			$a->before_status[10]->v = $a->vit;
			$a->vit = 0;
		}
		$a->before_status[10]->on = 1;
		$_SESSION['show'] .= $a->name."耐下降${v}(剩余3回合)。<p>";
		
		return 10;
	}

	/** 耐上升30 3回合**/
	public static function vit_up_30($a) {
		if(self::pre_uudd($a,83) == 0 || self::pre_uudd($a,11) == 0) {
			return 0;
		}
		$a->vit +=30;
		$a->before_status[83]->on = 1;
		$_SESSION['show'] .= $a->name."耐力上升30(剩余3回合)。<p>";
		
		return 83;
	}

	/** 运下降20 3回合 
	 **/
	public static function luk_down_20($a) {
		if(self::pre_uudd($a,77) == 0 || self::pre_uudd($a,73) == 0) {
			return 0;
		}
		$a->luk = ($a->luk-20>0) ? $a->luk-20 : 0;
		$a->before_status[77]->on = 1;
		$_SESSION['show'] .= $a->name."运下降20(剩余3回合)。<p>";
		
		return 77;
	}
	
	/** 全能力上升20 3回合 
	 **/
	public static function all_up_20($a,$this) {
		if(self::pre_uudd($a,11) == 0) {
			return 0;
		}
		self::goodestroy($a);
		$v = 20;
		$a->str += $v;
		$a->mgr += $v;
		$a->spd += $v;
		$a->vit += $v;
		$a->before_status[11]->on = 1;
		$a->before_status[11]->v = $v;
		if($sk->bufftime == 1) $a->before_status[11]->time += 1;
		$_SESSION['show'] .= $a->name."全能力上升${v}(剩余3回合)。<p>";
		
		return 11;
	}
	
	/** 全能力上升5 3回合 
	 **/
	public static function all_up_5($a) {
		if(self::pre_uudd($a,51) == 0) {
			return 0;
		}
		self::goodestroy($a);
		$a->str +=5;
		$a->mgr +=5;
		$a->spd +=5;
		$a->vit +=5;
		$a->before_status[51]->on = 1;
		$_SESSION['show'] .= $a->name."全能力上升5(剩余3回合)。<p>";
		
		return 11;
	}

	/** 全能力下降20 3回合 
	 **/
	public static function all_down_20($a) {
		if(self::pre_uudd($a,12) == 0) {
			return 0;
		}
		self::badestroy($a);
		$v = 20;
		$a->str = ($a->str-$v>0) ? $a->str-$v : 0;
		$a->mgr = ($a->mgr-$v>0) ? $a->mgr-$v : 0;
		$a->spd = ($a->spd-$v>0) ? $a->spd-$v : 0;
		$a->vit = ($a->vit-$v>0) ? $a->vit-$v : 0;
		$a->before_status[12]->on = 1;
		$a->before_status[12]->v = $v;
		$_SESSION['show'] .= $a->name."全能力下降${v}(剩余3回合)。<p>";	
		
		return 12;
	}

	/** 全能力下降30 陰業专用 3回合 
	 **/
	public static function all_down_30($a) {
		if(self::pre_uudd($a,76) == 0) {
			return 0;
		}
		self::badestroy($a);
		self::goodestroy($a);
		if($a->str-30 > 0) {
			$a->dstr = 30;
			$a->str -= 30;
		} else {
			$a->dstr = $a->str;
			$a->str = 0;
		}
			
		if($a->mgr-30 > 0) {
			$a->dmgr = 30;
			$a->mgr -= 30;
		} else {
			$a->dmgr = $a->mgr;
			$a->mgr = 0;
		}

		if($a->spd-30 > 0) {
			$a->dspd = 30;
			$a->spd -= 30;
		} else {
			$a->dspd = $a->spd;
			$a->spd = 0;
		}

		if($a->vit-30 > 0) {
			$a->dvit = 30;
			$a->vit -= 30;
		} else {
			$a->dvit = $a->vit;
			$a->vit = 0;
		}

		$a->before_status[76]->on = 1;
		$_SESSION['show'] .= $a->name."全能力下降30(剩余3回合)。<p>";	
		
		return 76;
	}

	/** 全能力上升30 3回合 パナケイアの祝福专用
	 **/
	public static function all_up_30($a) {
		if(self::pre_uudd($a,13) == 0) {
			return 0;
		}
		self::goodestroy($a);
		$a->str +=30;
		$a->mgr +=30;
		$a->spd +=30;
		$a->vit +=30;
		$a->before_status[13]->on = 1;
		$_SESSION['show'] .= $a->name."全能力上升30(剩余3回合)。<p>";
		
		return 13;
	}

	// 3回合 観世音の済度专用
	public static function relief($a,$mark) {
		self::goodestroy($a);
		self::badestroy($a);
		$upnum = ($mark == 1) ? 50 : 30;
		$a->str += $upnum;
		$a->mgr += $upnum;
		$a->spd += $upnum;
		$a->vit += $upnum;
		if($mark == 0) {
			$a->before_status[18]->on = 1;
			$_SESSION['show'] .= $a->name."发动観世音の済度<br>";
		} else {
			$a->before_status[79]->on = 1;
			$_SESSION['show'] .= "真.観世音の済度解放！";
		}	
		
		return 1;
	}

	/** 混沌迷雾 **/
	public static function chaosfog($a) {
		if($a->defskill_status[10]->on == 1) {
			$_SESSION['show'] .= $a->name."的身影在迷雾中更加模糊了...<br>";
			return 0;
		}
/*
		list($g,$pos) = CalHelper::getitbyuuid($a->uuid);
		$a->truename = $a->name;
		switch($pos) {
			case 0:{$a->name = 'A';break;}
			case 1:{$a->name = 'B';break;}
			case 2:{$a->name = 'C';break;}
			case 3:{$a->name = 'D';break;}
			default:{$a->name = '?';break;}
		}
		$a->name = strtoupper($g).$a->name;
*/
		$a->before_status[79]->on = 1;
		$a->defskill_status[10]->on = 1;
		return 1;
	}
	
	/** 全能力上升50 5回合 真.神恩のラッパ专用 
	 **/
	public static function all_up_50($a) {
		if(self::pre_uudd($a,13) == 0) {
			return 0;
		}
		self::goodestroy($a);
		$a->str +=50;
		$a->mgr +=50;
		$a->spd +=50;
		$a->vit +=50;
		$a->before_status[19]->on = 1;
		$_SESSION['show'] .= $a->name."全能力上升50(剩余5回合)。<p>";
		
		return 19;
	}
	
	//运成为0，$t：目标对象
	public static function zero_luk($t) {
		if(self::pre_uudd($t,73) == 0) {
			return 0;
		}
		//取消运下降20状态
		if($t->before_status[77]->on == 1) {
			$t->before_status[77]->cancel($t);
		}
		$t->oluk = $t->luk; //记录目标原始LUK
		$t->luk = 0;
		$t->before_status[73]->on = 1;
		return 73;
	}

	// 脱衣状态 2回合 
	public static function clothdown($a,$t) {
		if(self::pre_uudd($t,53) == 0) {
			return 0;
		}
		$t->before_status[53]->on = 1;
		$t->before_status[53]->committer = $a->uuid;
		return 1;
	}

	/** 场地破坏函数
	 * $odds:成功概率，返回0表示失败，返回1则成功，隐藏地形无法破坏
	**/
	public static function destroy_ground($odds) {
		if ($odds >= mt_rand(1,100) && $_SESSION['T'] < 7) {
	   		$_SESSION['T'] = 0;
    			$_SESSION['show'] .= "场地已被破坏。<br>";
			return 1;
		} else {
    			$_SESSION['show'] .= "场地破坏失败。<br>";
			return 0;
		}
	}

	//伤害后触发事件判断函数，目前判断两种全门耐性
	public static function afterdamage_event($t) {
		if($t->eventskill_status[21]->on == 1) $t->eventskill_status[21]->action($t);
		if($t->eventskill_status[22]->on == 1) $t->eventskill_status[22]->action($t);
/*
		if($t->eventskill_status[20]->on == 1) $t->eventskill_status[20]->action($t);
		if($t->eventskill_status[3]->on == 1) $t->eventskill_status[3]->action($t);

*/
	}
	
	/** 淀んだ吐息 3回合 
	 *	
	 **/
	public static function bad_blow($a,$b) {
		if($a->turnskill_status[0]->on == 1) {
			$_SESSION['show'] .= "淀んだ空気生效中，淀んだ吐息无效。<p>";
			return 0;
		} 
		$a->defskill_status[2]->on = 1;
		$a->defskill_status[2]->name = '淀んだ吐息';
		$b->defskill_status[2]->on = 1;
		$b->defskill_status[2]->name = '淀んだ吐息';
		$_SESSION['show'] .= $a->name."、".$b->name."异常被附加率上升15%(剩余3回合)。<p>";	

		return 1;
	}

	/** 淀んだ空気 3回合 
	 *	
	 **/
	public static function bad_air($a) {
		if($a->turnskill_status[0]->on == 1) {
			$_SESSION['show'] .= "同类场地技生效中，淀んだ空気无效。<p>";
			return 0;
		}
		if($a->defskill_status[2]->on == 1) {
			$a->defskill_status[2]->cancel($a);	//覆盖淀んだ吐息
		}
		$a->defskill_status[2]->on = 1;
		$a->turnskill_status[0]->on = 1;
		$_SESSION['show'] .= $a->name."异常被附加率上升15%(剩余3回合)。<p>";	

		return 1;
	}
	
	/** リベリオン 3回合 
	 *	
	 **/
	public static function AllCrtUp1($a) {
		if($a->atkskill_status[2]->on == 1 || $a->atkskill_status[3]->on == 1) {
			$_SESSION['show'] .= "同类场地技生效中，リベリオン无效。<p>";
			return 0;
		}
		$a->turnskill_status[2]->on = 1;
		$a->atkskill_status[2]->on = 1;
		$_SESSION['show'] .= $a->name."会心率上升15%(剩余3回合)。<p>";	
		
		return 1;
	}

	/** レボリューション 3回合 
	 *	
	 **/
	public static function AllCrtUp2($a) {
		if($a->atkskill_status[2]->on == 1 || $a->atkskill_status[3]->on == 1) {
			$_SESSION['show'] .= "同类场地技生效中，レボリューション无效。<p>";
			return 0;
		} 
		$a->turnskill_status[3]->on = 1;
		$a->atkskill_status[3]->on = 1;
		$_SESSION['show'] .= $a->name."会心率上升30%(剩余3回合)。<p>";
		
		return 1;
	}

	/** 会心の予言 3回合 **/
	public static function crtup($a,$sk) {
		if($a->before_status[52]->on == 1) {
			$_SESSION['show'] .= $sk->name."生效中，不能重复使用。<p>";
			return 0;
		}
		$a->atkskill_status[14]->on = 1;
		if($sk->ex == 1) {
			$a->atkskill_status[14]->v = 20;
		} else {
			$a->atkskill_status[14]->v = 10;
		}
		$a->before_status[52]->on = 1;
	}

        /** 二十八宿の守護 3回合
         *
         **/
        public static function stars_guard($a) {
                if($a->defskill_status[6]->on == 1) {
                        $_SESSION['show'] .= "二十八宿の守護已生效，无法重复使用。<p>";
                        return 0;
                }
                $a->defskill_status[6]->on = 1;
		$a->turnskill_status[1]->on = 1;
                $_SESSION['show'] .= $a->name."完全免疫异常和能力下降效果(剩余3回合)<p>";

                return 1;
        }

	/** チャージ 1回合 
	 *	
	 **/
	public static function phydmgdouble($a) {
		if($a->atkskill_status[4]->on == 1) {
			$_SESSION['show'] .= "蓄力生效中，不能重复执行。<br>";
			return 0;
		} 
		if($a->eventskill_status[25]->on == 1) {
			$_SESSION['show'] .= $a->name."受到地獄のマスク的影响，刚蓄上的力气马上就泄了……<br>";
			return 0;
		}
		$a->atkskill_status[4]->on = 1;
		
		return 1;
	}

	/** コンセントレイト 1回合 
	 *	
	 **/
	public static function mgrdmgdouble($a) {
		if($a->atkskill_status[5]->on == 1) {
			$_SESSION['show'] .= "精神集中生效中，不能重复执行。<br>";
			return 0;
		} 
		if($a->eventskill_status[25]->on == 1) {
			$_SESSION['show'] .= $a->name."受到地獄のマスク的影响，刚集中好的精神马上就乱了……<br>";
			return 0;
		}
		$a->atkskill_status[5]->on = 1;
		
		return 1;
	}

	/** トリプルチャージ 1回合 
	 *	
	 **/
	public static function doubledmgdouble($a) {
		if($a->atkskill_status[9]->on == 1) {
			$_SESSION['show'] .= "トリプルチャージ生效中，不能重复执行。<br>";
			return 0;
		} 
		if($a->eventskill_status[25]->on == 1) {
			$_SESSION['show'] .= $a->name."受到地獄のマスク的影响，蓄力集中无效……<br>";
			return 0;
		}
		$a->atkskill_status[9]->on = 1;
		
		return 1;
	}

	/** 夜之女王 
	* $t：使用者；$mark：1为真夜，0为普通
	**/
	public static function nightqueen($t,$mark) {
		if($t->before_status[48]->on == 1) {
			$_SESSION['show'] .= "夜之女王发动中，重复使用无效。<br>";
			return 0;
		}
		if($mark == 1) {
			$t->atkskill_status[8]->on = 1;
		} else {
			$t->atkskill_status[9]->on = 1;
		}
		$t->before_status[48]->on = 1;
		return 1;
	}

	/** 满月女王 
	* $t：使用者；$mark：1为真满月，0为普通满月
	**/
	public static function moonqueen($t,$mark) {
		if($t->before_status[49]->on == 1) {
			$_SESSION['show'] .= "满月女王发动中，重复使用无效。<br>";
			return 0;
		}
		if($mark == 1) {
			$t->atkskill_status[10]->on = 1;
		} else {
			$t->atkskill_status[11]->on = 1;
		}
		$t->before_status[49]->on = 1;
		return 1;
	}

	/** 黑裙子
	* $t：使用者；$mark：1为真黑裙子，0为普通
	**/
	public static function black_dress($t,$mark) {
		if($t->before_status[50]->on == 1) {
			$_SESSION['show'] .= "闇夜のドレス发动中，重复使用无效。<br>";
			return 0;
		}
		if($mark == 1) {
			$t->defskill_status[7]->on = 1;
		} else {
			$t->defskill_status[8]->on = 1;
		}
		$t->before_status[50]->on = 1;
		return 1;
	}

	/** ノルンの瞬き
	* $t：使用者；$mark：1为真ノルンの瞬き，0为普通
	**/
	public static function norns($t,$mark) {
		if($t->before_status[54]->on == 1 || $t->before_status[55]->on == 1) {
			$_SESSION['show'] .= "ノルンの瞬き发动中，重复使用无效。<br>";
			return 0;
		}
		if($mark == 1) {
			$t->before_status[54]->on = 1;
		} else {
			$t->before_status[55]->on = 1;
		}
		return 1;
	}

	/** 却火召喚
	* $t：使用者,$mark：1为真，0为普通
	**/
	public static function summon_fire($t,$mark) {
		if($t->before_status[51]->on == 1 || $t->before_status[52]->on == 1) {
			$_SESSION['show'] .= "却火召喚发动中，重复使用无效。<br>";
			return 0;
		}
		if($mark == 1) {
			$t->before_status[51]->on = 1;
		} else {
			$t->before_status[52]->on = 1;
		}
		$t->defskill_status[9]->on = 1;
		$t->atkskill_status[12]->on = 1;
		return 1;
	}

	/** 勝利の戦火
	* $t：被使用者,$mark：1为真，0为普通
	**/
	public static function victory_fire($t,$mark) {
		if($t->before_status[57]->on == 1) {
			$_SESSION['show'] .= "勝利の戦火发动中，重复使用无效。<br>";
			return 0;
		}
		if($mark == 1) {
			$t->atkafter_status[4]->on = 1;
		} else {
			$t->atkafter_status[5]->on = 1;
		}
		$t->before_status[57]->on =1;
		return 1;
	}

	/** 極彩の疾風
	* $t：使用者
	**/
	public static function cwind($t) {
		if($t->before_status[59]->on == 1) {
			$_SESSION['show'] .= "極彩の疾風发动中，重复使用无效。<br>";		
			return 0;
		}
		$a->spd += 30;
		$t->before_status[59]->on = 1;
		$t->atkskill_status[21]->on = 1;
		//$t->defskill_status[14]->on = 1;
		return 1;
	}
	
	/** 赤のカポーテ
	* $t：被使用者
	**/
	public static function rcloak($t) {
		if($t->before_status[58]->on == 1) {
			$_SESSION['show'] .= "赤のカポーテ发动中，重复使用无效。<br>";		
			return 0;
		}
		$t->before_status[58]->on = 1;
		$t->defskill_status[32]->on = 1;
		return 1;
	}
	
	/** 黒い神の開目
	* $t：使用者
	**/
	public static function openeye($t) {
		if($t->before_status[78]->on == 1) {
			$_SESSION['show'] .= "黒い神の開目发动中，重复使用无效。<br>";		
			return 0;
		}
		$t->str += 30;
		$t->before_status[78]->on = 1;
		$t->atkskill_status[51]->on = 1;
		//$t->defskill_status[14]->on = 1;
		return 1;
	}

	/** 天の鼓動
	* $t：使用者
	**/
	public static function skyencourage($t) {
		if($t->before_status[50]->on == 1) {
			$_SESSION['show'] .= "天の鼓動发动中，重复使用无效。<br>";		
			return 0;
		}
		$t->before_status[50]->on = 1;
		$t->defskill_status[29]->on = 1;
		return 1;
	}

	/** 异常前置处理
	  * $t：目标人对象 $mark，要求判断的是肉体异常还是精神异常，0为肉体，1为精神;$sk：技能对象
	  * 返回1，继续异常函数，返回0，则中止
	**/
	public static function pre_status($t,$mark,$sk) {
		
		if($t->isboss == 1) {	//BOSS无视万能异常
			$sk->god_abn = 0;
		}

		if($t->before_status[0]->on == 1 || $t->standing == 1) {
			$_SESSION['show'] .= $t->name."处于Down状态，无法附加异常。<br>";
			return 0;
		}

		if($t->defskill_status[6]->on == 1 && !$sk->god_abn) {
			$_SESSION['show'] .= $t->name."受到二十八星宿的守护，无法附加异常。<br>";
			return 0;
		}

		if($t->before_status[47]->on == 1 && !$sk->god_abn) {
			$_SESSION['show'] .= $t->name."受到聖者の歌的守护，无法附加异常。<br>";
			return 0;
		}
		
		if($t->eventskill_status[25]->on == 1) {
			$_SESSION['show'] .= $t->name."受到地獄のマスク的保护，无法附加异常。<br>";
			return 0;
		}

		if($sk->superabn != 1) { //超级异常不遵循常规替换判定
			$bstat=self::has_babn($t);
			$mstat=self::has_mabn($t);
		
			if($mark == 0) {
				if($bstat != 0) {
					$_SESSION['show'] .= $t->name."已中其它肉体异常，无法附加同类异常。<br>";
					return 0;
				}
			} else {
				if($mstat != 0) {
					$_SESSION['show'] .= $t->name."已中其它精神异常，无法附加同类异常。<br>";
					return 0;
				}
			}
		}

		return 1;
	}

	/** 判断是否异常突破，1为突破，0为不突破 **/
	public static function conquer_abn($t) {
		$tmp = mt_rand(1,100);
		$_SESSION['show'] .= "异常幸运数：".$tmp."<br>";
		return (round(($t->luk/2-10) * 1.3) >= $tmp) ? 1 : 0;
	}

	/** 隐者组别特技妖精之粉发动判断 **/
	public static function elf_powder($t) {
		if(CalHelper::ifgroupskill($t) == 9 && $t->groupskcount < 2) {
			$tmp = mt_rand(1,100);
			if(45 >= $tmp) {
				$_SESSION['show'] .= $t->name."发动妖精の粉，异常无效化<p>";
				$t->groupskcount += 1;
				return 1;
			}
		}
		return 0;
	}

	/** 塔组别技能混沌的波纹判断 **/
	public static function chaos_wave($a,$b,$sk,$function) {
		if(CalHelper::ifgroupskill($b) == 16 && $b->groupskcount == 0 && $b->hp < round($b->mxhp/3)) {
			$sk2 = clone $sk;
			$sk2->god_abn = 1;
			$b->groupskcount += 1;
			$_SESSION['show'] .= $b->name."发动混沌の波紋，异常反噬！<br>";
			self::$function($b,$a,-100,$sk2);
			$sk2 = NULL;
			return 1;
		}
		return 0;
	}

	/** 
	 * 中毒
	 * 影响状态位：before_status[20]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function poison($a,$b,$base,$sk){
	
		//无效状态判断
		if(self::pre_status($b,0,$sk) == 0){
			return 0;
		}
		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$s = "中毒异常成功率：".$h."<br>";
		$_SESSION['result'] .= $s;
		if($h >= $tmp){
			if($b->eventskill_status[7]->on == 1 || $b->eventskill_status[12]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>毒防御</font><br>";
					return 0;
				}
			}
			if(self::elf_powder($b) == 1) {
				return 0;
			}
			self::cure_mentalspt($b);
			$b->before_status[20]->on = 1;
			self::after_abn($a,$b,$sk,'poison');
			$_SESSION['show'] .= $a->name."对".$b->name."施毒成功！ 乱数:".$tmp."<p>";
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."施毒失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 衰弱
	 * 影响状态位：before_status[21]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function weak($a,$b,$base,$sk){

		//无效状态判断
		if(self::pre_status($b,0,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$s = "衰弱异常成功率：".$h."<br>";
		$_SESSION['result'] .= $s;
		if($h >= $tmp){
			if($b->eventskill_status[8]->on == 1 || $b->eventskill_status[12]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>衰弱防御</font><br>";
					return 0;
				}
			}
			self::cure_mentalspt($b);
			$b->before_status[21]->on = 1;
			$_SESSION['show'] .= $a->name."对".$b->name."衰弱成功！ 乱数:".$tmp."<p>";
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."衰弱失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 封印
	 * 影响状态位：before_status[22]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function close($a,$b,$base,$sk){

		//无效状态判断
		if(self::pre_status($b,0,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$s = "封印异常成功率：".$h."<br>";
		$_SESSION['result'] .= $s;
		if($h >= $tmp){
			if($b->eventskill_status[9]->on == 1 || $b->eventskill_status[12]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>封印防御</font><br>";
					return 0;
				}
			}
			if(self::elf_powder($b) == 1) {
				return 0;
			}
			self::cure_mentalspt($b);
			$b->before_status[22]->on = 1;
			self::after_abn($a,$b,$sk,'close');
			$_SESSION['show'] .= $a->name."对".$b->name."封印成功！ 乱数:".$tmp."<p>";
			if(CalHelper::ifgroupskill($a) == 15 && $a->groupskcount == 0) {
				$b->before_status[22]->time += 1;
				$a->groupskcount += 1;
				$_SESSION['show'] .= $a->name."发动邪念流動，封印持续回合+1！<br>";
			}
			self::chaos_wave($a,$b,$sk,__FUNCTION__);
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."封印失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 麻痹 
	 * 影响状态位：before_status[23]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function pala($a,$b,$base,$sk){
		
		//无效状态判断
		if(self::pre_status($b,0,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$_SESSION['result'] .= "麻痹异常成功率：".$h."<br>";
		if($h >= $tmp){
			if($b->eventskill_status[10]->on == 1 || $b->eventskill_status[12]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>麻痹防御</font><br>";
					return 0;
				}
			}
			self::cure_mentalspt($b);
			$b->before_status[23]->on = 1;
			self::after_abn($a,$b,$sk,'pala');
			$_SESSION['show'] .= $a->name."对".$b->name."麻痹成功！ 乱数:".$tmp."<p>";
			if(CalHelper::ifgroupskill($a) == 15 && $a->groupskcount == 0) {
				$b->before_status[23]->time += 1;
				$a->groupskcount += 1;
				$_SESSION['show'] .= $a->name."发动邪念流動，麻痹持续回合+1！<br>";
			}
			self::chaos_wave($a,$b,$sk,__FUNCTION__);
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."麻痹失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 老化 
	 * 影响状态位：before_status[24]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function old($a,$b,$base,$sk){

		//无效状态判断
		if(self::pre_status($b,0,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$s = "老化异常成功率：".$h."<br>";
		$_SESSION['result'] .= $s;
		if($h >= $tmp){
			if($b->eventskill_status[8]->on == 1 || $b->eventskill_status[12]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>老化防御</font><br>";
					return 0;
				}
			}
			self::cure_mentalspt($b);
			$b->before_status[24]->on = 1;
			$b->atkskill_status[12]->on = 1;
			$b->str = ($a->str - 5 < 0) ? 0 : $b->str - 5;
			$b->mgr = ($a->mgr - 5 < 0) ? 0 : $b->mgr - 5;
			$b->vit = ($a->vit - 5 < 0) ? 0 : $b->spd - 5;
			$b->spd = ($a->spd - 5 < 0) ? 0 : $b->vit - 5;
			self::after_abn($a,$b,$sk,'old');
			$_SESSION['show'] .= $a->name."对".$b->name."老化成功！ 乱数:".$tmp."<p>";
			self::chaos_wave($a,$b,$sk,__FUNCTION__);
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."老化失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 石化- 超级异常
	 * 影响状态位：before_status[80]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function stone($a,$b,$base,$sk){

		//无效状态判断
		if(self::pre_status($b,0,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$s = "石化异常成功率：".$h."<br>";
		$_SESSION['result'] .= $s;
		if($h >= $tmp){
			if($b->eventskill_status[12]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>仁王立防御</font><br>";
					return 0;
				}
			}
			self::cure_mentalspt($b);
			self::cure_bodyspt($b);
			$b->before_status[80]->on = 1;
			$b->defskill_status[30]->on = 1;
			#$b->vit += 100;
			$_SESSION['show'] .= $a->name."对".$b->name."石化成功！ 乱数:".$tmp."<p>";
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."石化失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 冻结 - 超级异常
	 * 影响状态位：before_status[84] 
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function freeze($a,$b,$base,$sk){

		//无效状态判断
		if(self::pre_status($b,0,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$s = "冻结异常成功率：".$h."<br>";
		$_SESSION['result'] .= $s;
		if($h >= $tmp){
			if($b->eventskill_status[12]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>仁王立防御</font><br>";
					return 0;
				}
			}
			self::cure_mentalspt($b);
			self::cure_bodyspt($b);
			$b->before_status[84]->on = 1;
			$b->defskill_status[31]->on = 1;
			$_SESSION['show'] .= $a->name."对".$b->name."冻结成功！ 乱数:".$tmp."<p>";
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."冻结失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 睡眠 - 超级异常
	 * 影响状态位：before_status[85] 
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function sleepit($a,$b,$base,$sk){

		//无效状态判断
		if(self::pre_status($b,0,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$s = "催眠异常成功率：".$h."<br>";
		$_SESSION['result'] .= $s;
		if($h >= $tmp){
			if($b->eventskill_status[18]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>不动心防御</font><br>";
					return 0;
				}
			}
			self::cure_mentalspt($b);
			self::cure_bodyspt($b);
			$b->before_status[85]->on = 1;
			$b->defskill_status[32]->on = 1;
			$_SESSION['show'] .= $a->name."对".$b->name."催眠成功！ 乱数:".$tmp."<p>";
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."催眠失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 激昂
	 * 影响状态位：before_status[25]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function high($a,$b,$base,$sk){

		//无效状态判断
		if(self::pre_status($b,1,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$s = "激昂异常成功率：".$h."<br>";
		$_SESSION['result'] .= $s;
		if($h >= $tmp){
			if($b->eventskill_status[13]->on == 1 || $b->eventskill_status[18]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>激昂防御</font><br>";
					return 0;
				}
			}
			if(self::elf_powder($b) == 1) {
				return 0;
			}
			self::cure_bodyspt($b);
			$b->before_status[25]->on = 1;
			self::after_abn($a,$b,$sk,'high');
			$_SESSION['show'] .= $a->name."对".$b->name."激昂成功！ 乱数:".$tmp."<p>";
			if($b->cid == 190) {
				$_SESSION['show'] .= $b->name."喊到，鲜血、狂暴……我丰收的时刻，到了！<p>";
			}
			self::chaos_wave($a,$b,$sk,__FUNCTION__);
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."激昂失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 魅惑 
	 * 影响状态位：before_status[26]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function lure($a,$b,$base,$sk){
		
		//无效状态判断
		if(self::pre_status($b,1,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$_SESSION['result'] .= "魅惑异常成功率：".$h."<br>";
		if($h >= $tmp){
			if($b->eventskill_status[14]->on == 1 || $b->eventskill_status[18]->on == 1 || $b->eventskill_status[19]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>魅惑防御</font><br>";
					return 0;
				}
			}
			if(self::elf_powder($b) == 1) {
				return 0;
			}
			self::cure_bodyspt($b);
			$b->before_status[26]->on = 1;
			$b->before_status[26]->committer = $a->uuid;
			$b->atkafter_status[3]->on = 1;
			$b->atkafter_status[3]->charmer = CalHelper::getitbyuuid($a->uuid);
				
			self::after_abn($a,$b,$sk,'lure');
			$_SESSION['show'] .= $a->name."对".$b->name."魅惑成功！ 乱数:".$tmp."<p>";
			self::chaos_wave($a,$b,$sk,__FUNCTION__);
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."魅惑失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 恐怖 
	 * 影响状态位：before_status[27]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function terror($a,$b,$base,$sk){
		
		//无效状态判断
		if(self::pre_status($b,1,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$_SESSION['result'] .= "恐怖异常成功率：".$h."<br>";
		if($h >= $tmp){
			if($b->eventskill_status[15]->on == 1 || $b->eventskill_status[18]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>恐怖防御</font><br>";
					return 0;
				}
			}
			if(self::elf_powder($b) == 1) {
				return 0;
			}
			self::cure_bodyspt($b);
			$b->before_status[27]->on = 1;

			if($a->uuid == $b->uuid) {
				$_SESSION['show'] .= $a->name."恐怖中！<p>";	//对撤退特别处理
			} else {
				self::after_abn($a,$b,$sk,'terror');
				$_SESSION['show'] .= $a->name."对".$b->name."恐怖成功！ 乱数:".$tmp."<p>";
				if(CalHelper::ifgroupskill($a) == 15 && $a->groupskcount == 0) {
					$b->before_status[27]->time += 1;
					$a->groupskcount += 1;
					$_SESSION['show'] .= $a->name."发动邪念流動，恐怖持续回合+1！<br>";
				}
			}
			self::chaos_wave($a,$b,$sk,__FUNCTION__);
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."恐怖失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 
	 * 混乱
	 * 影响状态位：before_status[28]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function confuse($a,$b,$base,$sk){

		//无效状态判断
		if(self::pre_status($b,1,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$s = "混乱异常成功率：".$h."<br>";
		$_SESSION['result'] .= $s;
		if($h >= $tmp){
			if($b->eventskill_status[16]->on == 1 || $b->eventskill_status[18]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>混乱防御</font><br>";
					return 0;
				}
			}
			if(self::elf_powder($b) == 1) {
				return 0;
			}
			self::cure_bodyspt($b);
			$b->before_status[28]->on = 1;
			self::after_abn($a,$b,$sk,'confuse');
			$_SESSION['show'] .= $a->name."对".$b->name."混乱成功！ 乱数:".$tmp."<p>";
			if(CalHelper::ifgroupskill($a) == 15 && $a->groupskcount == 0) {
				$b->before_status[28]->time += 1;
				$a->groupskcount += 1;
				$_SESSION['show'] .= $a->name."发动邪念流動，混乱持续回合+1！<br>";
			}
			self::chaos_wave($a,$b,$sk,__FUNCTION__);
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."混乱失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}
	
	/** 
	 * 诅咒
	 * 影响状态位：before_status[29]
	 * $base: 基数
	 * $hit: 技能加成
	 * $multi: 全体减成
	 **/
	public static function curse($a,$b,$base,$sk){
		
		//无效状态判断
		if(self::pre_status($b,1,$sk) == 0){
			return 0;
		}

		$h = CalHelper::abn_cal($a,$b,$base,$sk->ahits,$sk->tgtnum);
		$tmp = mt_rand(1,100);
		$_SESSION['result'] .= "诅咒异常成功率：".$h."<br>";
		if($h >= $tmp){
			if($b->eventskill_status[17]->on == 1 || $b->eventskill_status[18]->on == 1) {
				if(!$sk->god_abn) { 
					$_SESSION['show'] .= "<font color=green>诅咒防御</font><br>";
					return 0;
				}
			}
			self::cure_bodyspt($b);
			$b->before_status[29]->on = 1;
			$b->atkskill_status[7]->on = 1;//反噬状态
			$_SESSION['show'] .= $a->name."对".$b->name."诅咒成功！ 乱数:".$tmp."<p>";
			return 1;
		}
		else {
			$_SESSION['show'] .= $a->name."对".$b->name."诅咒失败！ 乱数:".$tmp."<p>";
			return 0;
		}
	}

	/** 异常后行为 **/
	public static function after_abn($a,$b,$sk,$type) {
		if($b->defskill_status[10]->on == 1) $b->defskill_status[10]->cancel($b);
		if(SkillHelper::ispureabnskill($sk) == 1){
			if(!isset($b->getabn)) $b->getabn = array();
			if(!in_array($type,$b->getabn)) {
				$b->getabn[] = $type;
				CalHelper::judgepoint($a,$b,'ABN');
			}
		}
		return 1;
	}

	/** 单个异常治疗函数 
	 * $a:发起人，$b:目标对象, $sk:技能对象, $status:对应的异常状态before_status位
	**/
	public static function cure_abn($a,$b,$sk,$status) {
		if($b->before_status[$status]->on == 0) {
			$_SESSION['show'] .= $b->name."未中".$b->before_status[$status]->name."状态，".$sk->name."无效。<br>";
		} else {
			$b->before_status[$status]->cancel($b);
			$_SESSION['show'] .= $b->name."的".$b->before_status[$status]->name."状态被解除了。<br>";
		}
		return 1;
	}

	/** 随机异常函数
	 * $a:发起人，$b:目标对象, $sk:技能对象, $base,基础确率,$limitabn,随机异常类型限制,0全常规异常1限制肉体常规2限制精神常规
	**/
	public static function random_abn($a,$b,$base,$sk,$limitabn=0) {
		switch($limitabn) {
			case 1:{$dlimit = 1;$ulimit = 4;break;}
			case 2:{$dlimit = 5;$ulimit = 8;break;}
			default:{$dlimit = 1;$ulimit = 8;break;}
		}
		switch(mt_rand($dlimit,$ulimit)) {
		case 1: {$_SESSION['result'] .= "本次判定异常为中毒<br>";self::poison($a,$b,$base,$sk);break;}
		case 2: {$_SESSION['result'] .= "本次判定异常为老化<br>";self::old($a,$b,$base,$sk);break;}
		case 3: {$_SESSION['result'] .= "本次判定异常为封印<br>";self::close($a,$b,$base,$sk);break;}
		case 4: {$_SESSION['result'] .= "本次判定异常为麻痹<br>";self::pala($a,$b,$base,$sk);break;}
		case 5: {$_SESSION['result'] .= "本次判定异常为激昂<br>";self::high($a,$b,$base,$sk);break;}
		case 6: {$_SESSION['result'] .= "本次判定异常为魅惑<br>";self::lure($a,$b,$base,$sk);break;}
		case 7: {$_SESSION['result'] .= "本次判定异常为恐怖<br>";self::terror($a,$b,$base,$sk);break;}
		case 8: {$_SESSION['result'] .= "本次判定异常为混乱<br>";self::confuse($a,$b,$base,$sk);break;}
		}
		return 1;
	}

	/** 小/大检查状态
	 * $a：发起人，$value：回避增加量
	**/
	public static function avoidup($a,$b,$value) {

		if($value == 10) {
			if($a->defskill_status[4]->on == 1 || $a->defskill_status[5]->on == 1) {
				$_SESSION['show'] .= "分析效果仍在作用中，不重计。<p>";
				return 0;
			}
			$a->defskill_status[4]->on = 1;
			$a->defskill_status[4]->committer = $b->uuid;
			$a->before_status[45]->on = 1;
			$_SESSION['show'] .= $a->name."对".$b->name."全回避上升${value}(剩余3回合)。<p>";
			return 1;
		}

		if($value == 20) {
			$a->defskill_status[4]->cancel($a);
			$a->before_status[45]->cancel($a);
			$a->defskill_status[5]->on = 1;
			$a->before_status[46]->on = 1;
			$_SESSION['show'] .= $a->name."全回避上升${value}(剩余3回合)。<p>";
			return 1;
		}

		return 1;
	}
	

	/** 空实现技能
	 * $b 目标对象 $did 关联的before_status编号 $name 技能名 $time 持续时间
	**/
	public static function dummies($b,$did,$name,$time) {
		if($b->before_status[$did]->on == 1) {
			$_SESSION['show'] .= $b->name."的".$name."效果发动中，不重计。<br>";
			return 0;
		}
		$b->before_status[$did]->on = 1;
		$_SESSION['show'] .= $b->name."受到".$name."效果影响，作用需人工判断(剩余".$time."回合)。<br>";
		
		return 1;
	}

	/** EXガードキル处理
	 * $b 目标对象 $bid 关联的before_status编号 $aid 关联的atkskill_status编号 $sk 技能
	**/
	public static function exguardkill($b,$bid,$aid,$sk) {
		if($b->before_status[$bid]->on == 1) {
			$_SESSION['show'] .= $b->name."的".$sk->name."效果发动中，不能重复生效。<br>";
			return  0;
		}
		$b->before_status[$bid]->on = 1;
		$b->atkskill_status[$aid]->on = 1;
		return 1;
	}

	//一切有利状态打消
	public static function goodestroy($t) {
		global $g_good_status;
		$effected = 0;
		foreach($g_good_status as $gid) {
			if($t->before_status[$gid]->on == 1) {
				$t->before_status[$gid]->cancel($t);
				if($effected == 0) {
					CalHelper::axiom_shield($t);	//摂理の盾
					$effected = 1;
				}
			}
		}
		return 1;
	}

	//一切不利状态打消
	public static function badestroy($t) {
		global $g_bad_status;
		foreach($g_bad_status as $bid) {
			if($t->before_status[$bid]->on == 1) {
				$t->before_status[$bid]->cancel($t);
			}
		}
		return 1;
	}

	//肉体异常恢复
	public static function cure_bodyspt($t) {
		global $g_body_spt;
		foreach($g_body_spt as $sid) {
			if($t->before_status[$sid]->on == 1) {
				$t->before_status[$sid]->cancel($t);
      			}
		}
	}

	//精神异常恢复
	public static function cure_mentalspt($t) {
		global $g_mental_spt;
		foreach($g_mental_spt as $sid) {
			if($t->before_status[$sid]->on == 1) {
  				$t->before_status[$sid]->cancel($t);
			}
		}
	}

	//一切异常恢复
	public static function cure_allspt($t) {
		global $g_all_spt;
		foreach($g_all_spt as $sid) {
			if($t->before_status[$sid]->on == 1) {
  				$t->before_status[$sid]->cancel($t);
		       		$_SESSION['show'] .= $t->name."从".$t->before_status[$sid]->name."状态中恢复了。<br>";
			}
		}
	}
	
	//一切特殊效果解除
	public static function cure_allspec($t) {
		foreach($t->spec_status as $ts) {
			if($ts->on == 1){
				$ts->cancel($t);
				$_SESSION['show'] .= $t->name."从".$ts->name."状态中恢复了。<br>";
			}
		}
		//解除绝望
		if($t->before_status[78]->on == 1) {
			$t->before_status[78]->cancel($t);
			$_SESSION['show'] .= $t->name."从绝望状态中恢复了。<br>";
		}
	}

	//蓄力集中效果全部打消
	public static function doubledestory($t) {
		$effected = 0;
		if($t->atkskill_status[4]->on == 1){
			$t->atkskill_status[4]->cancel($t);	//蓄力打消
			if($effected == 0) {
				CalHelper::axiom_shield($t);	//摂理の盾
				$effected = 1;
			}
		}
		if($t->atkskill_status[5]->on == 1){
			$t->atkskill_status[5]->cancel($t);	//集中打消
			if($effected == 0) {
				CalHelper::axiom_shield($t);	//摂理の盾
				$effected = 1;
			}
		}
		if($t->atkskill_status[9]->on == 1){
			$t->atkskill_status[9]->cancel($t);	//蓄力集中打消
			if($effected == 0) {
				CalHelper::axiom_shield($t);	//摂理の盾
				$effected = 1;
			}
		}
	}

	//天之王座处理
	public static function sky_thorne($a) {
		if(CalHelper::ifgroupskill($a) == 5 && $a->groupskcount == 0) {
			$_SESSION['show'] .= "天の王座发动！".$a->name."能力恢复并提升<br>";
			$healhp = round($a->mxhp * 0.20);
			$healsp = round($a->mxsp * 0.20);
			$a->hp = (($a->hp + $healhp) > $a->mxhp) ? $a->mxhp : ($a->hp + $healhp);
			$a->sp = (($a->sp + $healsp) > $a->mxsp) ? $a->mxsp : ($a->sp + $healsp);
			self::all_up_5($a);
			$a->groupskcount += 1;
			return 1;
		}
		return 0;
	}

	//输出当前所中的状态，非全部。为效率考虑，暂未采用全数组遍历的方式，而进行选择性处理
	public static function status_output($t) {
		foreach($t->before_status as $ts) {
                	if($ts->on == 1 && !$ts->nohint){
				if($ts->time > 5 || $ts->n == 0) $ntime = "";
				else $ntime = "(T".$ts->n.")";
                		echo $ts->name.$ntime."&nbsp;";
                	}
		}

		$askills_for_hint=array(2,3,4,5,9,53,54);
		foreach($askills_for_hint as $as) {
                	if($t->atkskill_status[$as]->on == 1){
				if($t->atkskill_status[$as]->n == 0) $ntime = "";
				else $ntime = "(T".$t->atkskill_status[$as]->n.")";
                		echo $t->atkskill_status[$as]->name.$ntime."&nbsp;";
                	}
		}

		$dskills_for_hint=array(2,6,7,9,23,24);
		foreach($dskills_for_hint as $ds) {
                	if($t->defskill_status[$ds]->on == 1){
				if($t->defskill_status[$ds]->n == 0) $ntime = "";
				else $ntime = "(T".$t->defskill_status[$ds]->n.")";
                		echo $t->defskill_status[$ds]->name.$ntime."&nbsp;";
               		}
		}

		$afskills_for_hint=array(12);
		foreach($afskills_for_hint as $afs) {
                	if($t->atkafter_status[$afs]->on == 1){
				if($t->atkafter_status[$afs]->n == 0) $ntime = "";
				else $ntime = "(T".$t->atkafter_status[$afs]->n.")";
                		echo $t->atkafter_status[$afs]->name.$ntime."&nbsp;";
               		}
		}
		
		$eskills_for_hint=array(23);
		foreach($eskills_for_hint as $es) {
                	if($t->eventskill_status[$es]->on == 1){
                		echo $t->eventskill_status[$es]->name."&nbsp;";
               		}
		}

		if($t->turnskill_status[5]->on == 1) {	//撤退
			echo "撤退(T".$t->turnskill_status[5]->n.")";
			
		}
		
	}

	//道具破坏函数，$odds，发动几率。$t，目标对象
	public static function crack_equip($odds,$t) {
		$_SESSION['result'] .= "道具破坏几率：".$odds."<br>";
		$tmp = mt_rand(1,100);
		$itemlist = array(
			$t->eventskill_status[4],	//破防
			$t->defskill_status[13],	//所罗门
			$t->atkskill_status[25],	//HB枪
			$t->atkskill_status[24],	//破耐枪
			$t->atkskill_status[8],		//破见切枪
			$t->atkskill_status[37],	//风枪
			$t->atkskill_status[38],	//雷枪
			$t->atkskill_status[39],	//地枪
			$t->atkskill_status[40],	//火枪
			$t->atkskill_status[41],	//冰枪
			$t->atkskill_status[42],	//元素枪
			$t->atkskill_status[43],	//睿者石
			$t->defafter_status[2],		//破环
		);
		$destroyed = 0;
		if($odds >= $tmp) {
			foreach($itemlist as $item) {
				if($item->on == 1) {
					$item->cancel($t);
					$_SESSION['show'] .= $t->name."装备的".$item->name."被破坏，乱数：".$tmp."<br>";
					$destroyed = 1;
				}
			}
			if($destroyed == 0) {
				$_SESSION['show'] .= $t->name."装备的道具已被破坏，乱数：".$tmp."<br>";
			}
		} else {
			$_SESSION['show'] .= "道具破坏失败，乱数：".$tmp."<br>";
		}
	}

	/** 撤退处理函数 **/
	public static function escape($a) {
		$a->escaping = 1;
		$a->turnskill_status[5]->on = 1;
		list($group,$key) = CalHelper::getitbyuuid($a->uuid);
		$tgroup = ($group == 'a') ? 'b' : 'a';
		$diff = CalHelper::fighter_count($_SESSION[$tgroup]) - CalHelper::fighter_count($_SESSION[$group]);
		if($diff > 0) {
			$_SESSION['show'] .= "本方有效战斗人员获得AP加成！<br>";
			foreach($_SESSION[$group] as $sg) {
				$sg->recoverap = $diff * 2;
				if($sg->escaping == 1 || $sg->hp <= 0) continue;
				CalHelper::apointchange_2($sg,$diff * 5);
			}
		}
		return 1;
	}

	//重置一切状态
	public static function resetall($a) {

		foreach($a->before_status as $as) {
                	if($as->on == 1 && !$as->permanent){
                		$as->cancel($a);
                	}
		}

		//排除场地技重置,下同
		$atkgstatus=array(2,3);
		foreach($a->atkskill_status as $as) {
			if(in_array($as->id,$atkgstatus)) continue;
                	if($as->on == 1 && !$as->permanent){
                		$as->cancel($a);
                	}
		}

		$defgstatus=array(2,6,10);
		foreach($a->defskill_status as $as) {
			if(in_array($as->id,$defgstatus)) continue;
                	if($as->on == 1 && !$as->permanent){
                		$as->cancel($a);
                	}
		}

		foreach($a->atkafter_status as $as) {
                	if($as->on == 1 && !$as->permanent){
                		$as->cancel($a);
                	}
		}

		foreach($a->defafter_status as $as) {
                	if($as->on == 1 && !$as->permanent){
                		$as->cancel($a);
                	}
		}
/*
		foreach($a->spec_status as $as) {
                	if($as->on == 1 && !$as->permanent){
                		$as->cancel($a);
                	}
		}
*/
		foreach($a->eventskill_status as $as) {
                	if($as->on == 1 && !$as->permanent){
                		$as->cancel($a);
                	}
		}
		
		$a->before_status[17]->started = 0;	//取消觉醒
		self::uskill_init($a); //重新启动专有被动
		return 1;
	}

}

?>
